﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraBars;
using DevExpress.XtraBars.Ribbon;
using DevExpress.XtraBars.Helpers;
using CNotebook;

namespace NotebookS2
{
    public partial class BRW_COA : RibbonForm
    {
        public BRW_COA()
        {
            InitializeComponent();
        }

        public string ConnectionString { get; set; }
        public string ActiveUserID { get; set; }


        void BindCOA()
        {
            ChartOfAccountManager oManager = new ChartOfAccountManager();

            oManager.ConnectionString = this.ConnectionString;
            oManager.Open();
            DataTable dt = oManager.GetChartOfAccounts();
            oManager.Close();

            treeList1.KeyFieldName = "AcctCode";
            treeList1.ParentFieldName = "FatherAcctCode";

            treeList1.DataSource = dt;
            treeList1.ExpandAll();
            treeList1.Refresh();
            
        }

        private void BRW_COA_Load(object sender, EventArgs e)
        {
            BindCOA();    
        }

        private void btnAddNewCOA_Click(object sender, EventArgs e)
        {
            M_ChartOfAccount oCOA = new M_ChartOfAccount();

            oCOA.ConnectionString = this.ConnectionString;
            oCOA.ActiveUserID = this.ActiveUserID;

            oCOA.ShowDialog();

            BindCOA();
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            BindCOA();
        }
    }
}